package com.lambda.springbootlambda.functionInterface;

/**
 * lambda中具有一个闭包的问题，就是lambda表达式中对象必须是final修饰的，
 * 即使我们没有添加，java虚拟机也会在运行的时候帮我们添加上
 * @author ytj
 * @date 2021/12/14
 */
public class FunctionalInterfaceTest {
    public static void main(String[] args) {
        MoreParamNoReturn moreParamNoReturn=(a,b)-> System.out.println("传递值为:"+a+","+b);
        moreParamNoReturn.method(1,2);
        MoreParamReturn moreParamReturn=(a,b)->a+b;
        int num=moreParamReturn.method(1,2);
        System.out.println("返回值为:"+num);
        NoParamNoReturn noParamNoReturn=()-> System.out.println("没有参数没有返回值");
        noParamNoReturn.method();
        NoParamReturn noParamReturn=()->"今天是个好天气";
        String result=noParamReturn.method();
        System.out.println("返回结果为:"+result);
        OneParamNoReturn oneParamNoReturn=(a)-> System.out.println("参数为:"+a+",没有返回值");
        oneParamNoReturn.method(1);
        OneParamReturn oneParamReturn=(a)->a;
        int results=oneParamReturn.method(1);
        System.out.println("一个参数没有返回值:"+results);

        OneParamReturn oneParamReturn1=a->addOne(a);
        System.out.println("test1:"+oneParamReturn1.method(1));
        OneParamReturn oneParamReturn2=FunctionalInterfaceTest::addOne;
        System.out.println("test2:"+oneParamReturn2.method(2));
    }

    public static int addOne(int a){
        return a+1;
    }
}
